<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>laytpl基础使用</title>
  <link rel="stylesheet" href="../../assets/layui/css/layui.css" />
  <script src="../../assets/layui/layui.all.js"></script>
</head>

<body>

  <!--第一步：编写模版。可以使用一个<script>标签存放模板，示例代码：-->
  <script id="demo" type="text/html">
      {{d.mydate}}
    </script>

  <!--第二步：建立视图。用于呈现渲染结果。-->
  <div id="view"></div>

  <!--第三步：渲染模版-->
  <script>
    var laytpl = layui.laytpl;
    var getTpl = demo.innerHTML;
    var data = {
      "mydate": "2020-1-1"
    };
    var view = document.getElementById('view');
    laytpl(getTpl).render(data, function (html) {
      view.innerHTML = html;
    });
  </script>
</body>

</html>